$(function(){
	$('#tt').datagrid({
		url:'/bruchTask/getBruchTaskListPage'
	});
	
});

function doAdd(){
	$('#addForm').form('clear');
	$('#addWin').window('open');
}

function doEdit(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$('#idId').val(record.id);
	$('#nameId').val(record.name);
	$('#classNameId').val(record.className);
	$('#taskNumId').val(record.taskNum);
	$('#speedId').val(record.speed);
	
	$('#addWin').window('open');
}

function updateStatus(status,msg){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$.messager.confirm('提示', msg, function(opt){
		if (opt){
			var bruchTaskId=record.id;
			$.ajax({
				url: '/bruchTask/updateBruchTaskStatus',
				type: 'POST',
				data : {
		            id:bruchTaskId,
		            status:status
				},
				success : function(data) {
					if (data.return_code == '1') {
						$.messager.alert(market.content.title, "操作成功");
						$("#tt").datagrid('reload');
						$('#tt').datagrid('unselectAll');
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				},
				error : function(e) {
					$.messager.alert("未知错误");
				}
			})
		}
	});	
	
}

function doSearch(){
	$('#tt').datagrid({
		url:'/bruchTask/getBruchTaskListPage',
		queryParams:{
		}
	});
	$('#tt').datagrid('unselectAll');
}

function save(){
	var id=$('#idId').val();
	var url='/bruchTask/updateBruchTask';
	if(id==null||id==''){
		url='/bruchTask/saveBruchTask';
	}
	
	$('#addForm').form('submit',{
		url : url,
		onSubmit : function() {
			var flag = $(this).form('validate');
			if (!flag) {
				return flag;
			}
			showProcess(true, market.content.title, market.content.submitting);
			return true;
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$('#tt').datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
	
}

function cancel(){
	$('#addWin').window('close');
}

function statusFormatter(value){
	if(value==1){
		return '<span style="color:green">启动</span>';
	}else{
		return '<span style="color:red">停止</span>';
	}
}
